home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 19 / macformat_19.iso / Shareware / Games / Star Flick / CT / Source / CToast.h < prev    next >
Text File  |  1994-02-07  |  14KB  |  400 lines

  1. /************************************************************************************
  2.  * CToast.h
  3.  *
  4.  * CheeseToast by Jim Bumgardner
  5.  *
  6.  ************************************************************************************/
  7.  
  8. #include <stdarg.h>
  9. #include "QDOffscreen.h"
  10. #if __option(profile)            // 6/15 Optional profiling support
  11. #include <profile.h>
  12. #endif
  13.  
  14. /*
  15.  * Constants
  16.  */
  17.  
  18. #define DEBUGGING        0        // Enable debugging key and debugging sprites
  19. #define MaxSprites        512        // Maximum simultaneous sprites (incl. bullets/shards)
  20. #define MaxSaveMaps        48        // Maximum Large Sprites
  21. #define MaxScoreRecords    10        // Number of top scores shown
  22. #define ColorMapSize    1024L    // Size of 32x32 8-bit sprite map
  23. #define MaskMapSize        128L    // Size of 32x32 1-bit MaskMap
  24. #define BulletMapSize    4L        // Size of 2x2 8-bit bullet map
  25. #define IconWidth        32        // Width of Icon
  26. #define IconHeight        32        // Height of Icon
  27. #define BulletWidth        2        // Width/Height of Bullet
  28. #define StartupPICT        128        // Starup Picture Resource ID
  29. #define BackgroundPICT    129        // Background Picture Resource ID
  30. #define SmallLogoPICT    131        // Small Logo Picture ID (Attract Mode)
  31. #define NbrAsteroids    3        // Number compound asteroids in table
  32. #define MaxAngles        32        // Number of vectors in vector table
  33. #define NbrYummies        5        // Number of tasty objects
  34. #define MaxShieldPower    100        // Maximum Shield Power
  35. #define AsterPoints        100        // Points for zapping an asteroid
  36. #define SaucerPoints    500        // Points for zapping a saucer
  37. #define BarbellPoints    600        // Points for zapping a barbell
  38. #define CubePoints        750        // Points for zapping a cube
  39. #define LevelBonusScore    1000    // Points for advancing to next level
  40.  
  41. #define TopScoreResType    'tScr'
  42. #define PrefsResType    'prfs'
  43.  
  44. /*
  45.  * Function Macros
  46.  */
  47.  
  48. #define AniFrameIndex(i)    (i << 10)    // Multiply by 1024 (ColorMapSize)
  49. #define AniRowIndex(i)        (i << 5)    // Multiply by 32 (rowsize)
  50.  
  51. /*
  52.  * Enumerated Types
  53.  */
  54.  
  55. // Ship Flags - are we firing?  turning? thrusting? shields up?
  56. //
  57. enum ShipFlags     {SF_Fire=0x01, SF_Left=0x02, SF_Right=0x04,
  58.                   SF_Thrust=0x08, SF_Shield=0x10};
  59.  
  60. // Sound IDs
  61. //
  62. enum Sounds         {S_Startup, S_Explosion, S_BadGuyDebut, S_ShipDebut, S_ShipExplodes,
  63.                    S_EnemyFires, S_Thrust, S_DudBullet, 
  64.                    S_LevelCompletion, S_CompoundFracture, S_Shield, S_YummyConsume,
  65.                    S_HighScore1, S_LetterDisplay, S_ExtraShip, S_Loser, S_Firing,
  66.                    S_HighScore2,
  67.                    S_NbrSounds};
  68.  
  69.  
  70. // Game Modes
  71. //
  72. enum GameStates    { GS_Attract, GS_Play, GS_GameOver };
  73.  
  74. // Visual Sprites types
  75. enum SpriteTypes {
  76.                   ST_Wheel, ST_Aster, ST_Teacup, ST_Jim,
  77.                   ST_WheelR, ST_WheelG, ST_WheelB, ST_Aster1, 
  78.                   ST_Aster2, ST_Saucer, ST_Barbell, ST_Cube,
  79.                   ST_Teapot,  ST_TeapotT, ST_TeapotS, ST_TeapotNew,
  80.                   ST_Yummies, ST_Bullet, ST_Photon, ST_Spark,
  81. // Logic Sprites
  82.                   ST_StatusDisplay,
  83. #if DEBUGGING
  84. // Debugging Sprites
  85.                   ST_SpriteCnt, ST_MaxSprite,
  86. #endif
  87.                   NbrSprites};
  88.  
  89. // Mask which identifies valid targets for "good bullets" (based on sprite type)
  90. #define BF_GoodBullet    0x00010FFF
  91.  
  92. // Mask which identifies valid targets for "bad bullets" (based on sprite type)
  93. #define    BF_BadBullet    0x0000F000
  94.  
  95. // Ship Modes (special guns, magic shield)
  96. enum ShipModes     {SM_Triple=1, SM_Uzi=2, SM_AutoShield=4};
  97.  
  98. /*
  99.  * Data Structures
  100.  */
  101.  
  102. // User Preferences - keyboard remapping, sound level, username
  103. typedef struct {
  104.     char    fireKeyByte, fireKeyBit, fireKeyCode, fireKeyAscii;
  105.     char    thrustKeyByte, thrustKeyBit, thrustKeyCode, thrustKeyAscii;
  106.     char    leftKeyByte, leftKeyBit, leftKeyCode, leftKeyAscii;
  107.     char    rightKeyByte, rightKeyBit, rightKeyCode, rightKeyAscii;
  108.     char    shieldKeyByte, shieldKeyBit, shieldKeyCode, shieldKeyAscii;
  109.     short    soundLevel;
  110.     Str31    userName;
  111.     char    reserved[30];
  112. } PrefsData;
  113.  
  114. // Sprite Vector Coordinate system uses fixed point arithmetic
  115. //
  116. typedef struct    {
  117.     long    lh,lv;
  118. } LongPoint;
  119.  
  120. // Data structure for saving the area of screen underneath sprite
  121. //
  122. typedef struct {
  123.     struct SpriteInstance    *sp;
  124.     short    active;
  125.     short    reserved;
  126.     char    saveMap[1024];
  127. } SaveMapRecord,*SaveMapPtr;
  128.  
  129. // Data structure for each sprite instance
  130. //
  131. typedef struct SpriteInstance {
  132.     Point        pos,oldPos;        // Sprite Coords
  133.     LongPoint    vector;            // Sprite Movement Velocity
  134.     short        type;            // Sprite Type - Index into Sprite Def Table
  135.     long        param1;            // Varies for each sprite type
  136.     short        param2;            // Varies for each sprite type
  137.     short        aniState;        // Animation Frame
  138.     short        aniSpeed;        // Animation Frame Rate
  139.     short        tickCtr;        // Time Counter
  140.     short        lifeSpan;        // Life Span of Sprite
  141.     short        angle;            // Index into Vector Table
  142.     short        width;            // Width of Sprite
  143.     Boolean        active,            // Sprite is Active
  144.                 update;            // Sprite needs updating onscreen
  145.     char        savePixel[4];
  146.     SaveMapPtr    saveMapPtr;
  147. } SpriteInstance;
  148.  
  149. // Sprite Definition Table - defines behavior for each variety of sprite
  150. // function pointers are used for drawing, erasing and moving
  151. //
  152. typedef struct {
  153.     short    type;
  154.     short    firstIconID;
  155.     short    nbrIcons;
  156.     void    (*moveFunc)(register SpriteInstance *sp);
  157.     void    (*eraseFunc)(register SpriteInstance *sp);
  158.     void    (*drawFunc)(register SpriteInstance *sp);
  159.     Ptr        colorMaps;
  160.     Ptr        maskMaps;
  161. } SpriteDef;
  162.  
  163. // Entry in "top 10" scores table
  164. //
  165. typedef struct {
  166.     long    score;
  167.     short    level;
  168.     Str31    name;
  169. } ScoreRecord;
  170.  
  171. /*
  172.  * Extern Variables - see below for comments
  173.  */
  174.  
  175. extern short        gResFile;
  176. extern GWorldPtr    gOffScreen;
  177. extern PixMapHandle    gPixMap;
  178. extern Boolean        g12InchMode;
  179. extern short        gMaxSprite,gSpriteCnt,gSparkCnt,gAsteroidCnt,gRemainingShips;
  180. extern short        gNbrSaveMaps;
  181. extern short        gYummyCnt;
  182. extern long            gScreenRowBytes,gVideoRowBytes;
  183. extern Ptr            gScreenMem,gVideoMem;
  184. extern Rect            gPlayRect,gOffscreenRect;
  185. extern Point        gCenterP,gVidOffset;
  186. extern long            gPlayWidth,gPlayHeight;
  187. extern long            gGameClockTicks;        // 20 Frames per Second
  188. extern long            gLastDispTime;
  189. extern short        gGameState,gGameLevel,gShipMode,gShieldPower;
  190. extern long            gGameScore;
  191. extern short        gScoreMultiply;
  192. extern SpriteDef    sDef[NbrSprites];
  193. extern LongPoint    vecTable[MaxAngles];
  194. extern ScoreRecord    scoreRecord[MaxScoreRecords];
  195. extern PrefsData    gPrefs;
  196. extern SaveMapRecord    *smTable;
  197. extern SpriteInstance    *sTable,*gShip;
  198.  
  199. /*
  200.  * Function Declarations
  201.  */
  202.  
  203. // Low level Display
  204. void MyCopyBits(void);
  205. void MyCopyBits12Inch(void);
  206. void MyCopyRect(register Rect *r);
  207.  
  208. // Picture Display
  209. void DisplayPicture(short picID, short hOffset, short vOffset);
  210.  
  211. // Game Control
  212. void InitializeGame(WindowPtr theWin);        // 1 Time only inits
  213. void CleanUp(void);                            // 1 Time only cleanup
  214. void MainGameLoop(WindowPtr theWin);
  215. void StartupScreen(void);
  216. void BeginAttract(void);
  217. void BeginGame(void);
  218. void EndGame(void);
  219. void InitLevel(void);
  220. void InitStatusDisplay(void);
  221. void StatusPrintf(short x, short y, char *tmp, ...);
  222. void PrintfXY(short x, short y, char *template, ...);
  223. void CenterString(StringPtr str);
  224. void DrawStatusBar(short curLevel, short maxLevel);
  225. void AddScore(short amt);
  226. void GetUserName(StringPtr name);
  227. void CheckKeys(void);
  228.  
  229. // Sprite Maintenence
  230. SpriteInstance *NewSprite(Boolean saveMapFlag);
  231. void KillSprite(SpriteInstance *sp);
  232. void NewShip(void);
  233. void NewSaucer(void);
  234. void NewBarbell(void);
  235. void NewCube(void);
  236. void NewAsteroid(short type);
  237. void NewYummy(void);
  238. void LaunchBullet(short type, short x, short y, long vx, long vy, short lifeSpan, long bTarget);
  239. void LaunchSpark(short x, short y, long vx, long vy, short lifeSpan, short color);
  240. void ExplodeSprite(register SpriteInstance *sp, register short lifeSpan);
  241.  
  242. // Util Funcs
  243. short min(register short x, register short y);
  244. short max(register short x, register short y);
  245.  
  246. #if DEBUGGING
  247. void NewDebugDisplay(void);
  248. #endif
  249.  
  250. // State Machine Functions
  251. void StandardSpriteErase(register SpriteInstance *);
  252. void StandardSpriteMove(register SpriteInstance *);
  253. void StandardSpriteDraw(register SpriteInstance *);
  254. void BulletErase(register SpriteInstance *);
  255. void BulletMove(register SpriteInstance *);
  256. void BulletDraw(register SpriteInstance *);
  257. void PhotonDraw(register SpriteInstance *);
  258. void SaucerMove(register SpriteInstance *);
  259. void BarbellMove(register SpriteInstance *);
  260. void CubeMove(register SpriteInstance *);
  261. void YummyMove(register SpriteInstance *sp);
  262. void ShipMove(register SpriteInstance *);
  263. void SparkErase(register SpriteInstance *);
  264. void SparkMove(register SpriteInstance *);
  265. void SparkDraw(register SpriteInstance *);
  266. void NewShipTimer(register SpriteInstance *);
  267. void NullFunc(register SpriteInstance *);
  268. void StatusDraw(register SpriteInstance *);
  269. void QuakeMove(register SpriteInstance *);
  270.  
  271. #if DEBUGGING
  272. void SpriteCntMove(register SpriteInstance *);
  273. void MaxSpriteMove(register SpriteInstance *);
  274. #endif
  275.  
  276.  
  277. // The following code is only compiled if "SPRITEMAIN" is turned on
  278. //
  279. #if SPRITEMAIN
  280.  
  281. // Note: I'm using fixed point arithmetic here - the upper word is used for
  282. // screen coords, this table was computed using Excel: Sin() * 65535
  283.  
  284. LongPoint    vecTable[MaxAngles] = {
  285.                 0L,            -65535L,
  286.                 12785L,        -64276L,
  287.                 25079L,        -60546L,
  288.                 36409L,        -54490L,
  289.                 46340L,        -46340L,
  290.                 54490L,        -36409L,
  291.                 60546L,        -25079L,
  292.                 64276L,        -12785L,
  293.                 65535L,        0L,
  294.                 64276L,        12785L,
  295.                 60546L,        25079L,
  296.                 54490L,        36409L,
  297.                 46340L,        46340L,
  298.                 36409L,        54490L,
  299.                 25079L,        60546L,
  300.                 12785L,        64276L,
  301.                 0L,            65535L,
  302.                 -12785L,    64276L,
  303.                 -25079L,    60546L,
  304.                 -36409L,    54490L,
  305.                 -46340L,    46340L,
  306.                 -54490L,    36409L,
  307.                 -60546L,    25079L,
  308.                 -64276L,    12785L,
  309.                 -65535L,    0L,
  310.                 -64276L,    -12785L,
  311.                 -60546L,    -25079L,
  312.                 -54490L,    -36409L,
  313.                 -46340L,    -46340L,
  314.                 -36409L,    -54490L,
  315.                 -25079L,    -60546L,
  316.                 -12785L,    -64276L};
  317.  
  318. GWorldPtr        gOffScreen;        // Offscreen Drawing Area
  319. short            gResFile;        // "CT Resources" file - contains sprites & snds
  320. PixMapHandle    gPixMap;        // Offscreen Pixel Map
  321. Boolean            g12InchMode;    // True if 512 x 384 mode, otherwise 640 x 480
  322. short            gMaxSprite,        // Maximum sprites onscreen
  323.                 gSpriteCnt,        // Number of sprites onscreen
  324.                 gSparkCnt,        // Number of sparks onscreen
  325.                 gAsteroidCnt,    // Number of asteroids onscreen
  326.                 gRemainingShips;    // Number of remaining free ships
  327. short            gNbrSaveMaps;    // Number of 32 x 32 savemaps in use
  328. short            gYummyCnt;        // Number of "Yummies" onscreen
  329. long            gScreenRowBytes,    // RowBytes for offscreen area
  330.                 gVideoRowBytes;    // RowBytes for onscreen video
  331. Ptr                gScreenMem,        // BaseAddr for offscreen area
  332.                 gVideoMem;        // BaseAddr for onscreen video
  333. Rect            gPlayRect,        // Bounds of legal sprite coordinates
  334.                 gOffscreenRect;    // Bounds of offscreen drawing area
  335. Point            gCenterP,        // Center of offscreen drawing area
  336.                 gVidOffset;        // Top,Left of onscreen Play field 
  337.                                 // in global coordinates
  338. long            gPlayWidth,        // Width of playing field
  339.                 gPlayHeight;    // Height of playing field
  340. long            gGameClockTicks = 3L;        
  341.                                 // 20 Frames per Second
  342. long            gGameClock;        // Incremented every 3 ticks
  343. long            gLastDispTime = 0L;
  344.                                 // Ticks of last frame
  345. short            gGameState,        // Attract=0,Play=1,GameOver=2
  346.                 gGameLevel,        // Game Level - effects difficulty
  347.                 gLastLevel,        // Last Level - used to update display
  348.                 gLastRemainingShips;  // Last Remaining Ships - used to update display
  349. short            gShipMode,        // Ship Modes - Magic Shield, Special Bullets
  350.                 gShieldPower,    // Power remaining in shields
  351.                 gLastShieldPower;    // Used to update display
  352. short            gScoreMultiply,    // Score Multiplier (times two, times three etc)
  353.                 gLastScoreMultiply;    // Used to update display
  354. long            gGameScore,        // Current Score
  355.                 gLastScore;        // Last Score - used to update display
  356. short            gBadGuyChance,    // Chance of bad guy appearing
  357.                 gYummyChance;    // Chance of Yummy appearing
  358. short            oldMBarHeight;    // Old Menu Bar Height
  359.  
  360. SpriteInstance    *sTable,        // Sprite Table
  361.                 *gShip;            // Pointer to Ship Sprite in sprite table, 
  362.                                 // for quick access
  363. SaveMapRecord    *smTable;        // Save Map Table
  364.  
  365. // Sprite Definition Table - defines behavior for each variety of sprite
  366. // function pointers are used for drawing, erasing and moving
  367. //
  368. SpriteDef sDef[NbrSprites] = {
  369. //  type      iconID nbrIcons  MoveFunction       EraseFunction        DrawFunction
  370. //  ----      -----  -------   ------------      ---------------     --------------
  371.     {ST_Wheel,     500, 12,    StandardSpriteMove, StandardSpriteErase, StandardSpriteDraw},
  372.     {ST_Aster,  700, 12,    StandardSpriteMove, StandardSpriteErase, StandardSpriteDraw},
  373.     {ST_Teacup, 600, 12,    StandardSpriteMove, StandardSpriteErase, StandardSpriteDraw},
  374.     {ST_Jim,     6000,12,    StandardSpriteMove, StandardSpriteErase, StandardSpriteDraw},
  375.     {ST_WheelR, 182, 12,    StandardSpriteMove, StandardSpriteErase, StandardSpriteDraw},
  376.     {ST_WheelG, 194, 12,    StandardSpriteMove, StandardSpriteErase, StandardSpriteDraw},
  377.     {ST_WheelB, 206, 12,    StandardSpriteMove, StandardSpriteErase, StandardSpriteDraw},
  378.     {ST_Aster1, 218, 12,    StandardSpriteMove, StandardSpriteErase, StandardSpriteDraw},
  379.     {ST_Aster2, 230, 12,    StandardSpriteMove, StandardSpriteErase, StandardSpriteDraw},
  380.     {ST_Saucer, 164, 18,    SaucerMove,            StandardSpriteErase, StandardSpriteDraw},
  381.     {ST_Barbell,4000,12,    BarbellMove,        StandardSpriteErase, StandardSpriteDraw},
  382.     {ST_Cube,    5000, 18,    CubeMove,             StandardSpriteErase, StandardSpriteDraw},
  383.     {ST_Teapot, 2000,16,    ShipMove,             StandardSpriteErase, StandardSpriteDraw},
  384.     {ST_TeapotT,2100,16,    ShipMove,             StandardSpriteErase, StandardSpriteDraw},
  385.     {ST_TeapotS,2200,16,    ShipMove,             StandardSpriteErase, StandardSpriteDraw},
  386.     {ST_TeapotNew, 0, 0,    NewShipTimer,        NullFunc,             NullFunc},
  387.     {ST_Yummies,3000, NbrYummies,    YummyMove,    NullFunc,              NullFunc},
  388.     {ST_Bullet,    0,      0,    BulletMove,            BulletErase,         BulletDraw},
  389.     {ST_Photon,    0,      0,    BulletMove,            BulletErase,         PhotonDraw},
  390.     {ST_Spark,    0,      0,    SparkMove,            SparkErase,             SparkDraw},
  391.     {ST_StatusDisplay, 0,0, NullFunc,            NullFunc,             StatusDraw},
  392. #if DEBUGGING
  393.     {ST_SpriteCnt, 0, 0,    SpriteCntMove,        BulletErase,         PhotonDraw},
  394.     {ST_MaxSprite, 0, 0,    MaxSpriteMove,        BulletErase,         PhotonDraw},
  395. #endif
  396.     };
  397.  
  398. #endif
  399.  
  400. /* End of CToast.h */